package com.vincent.core.vo;

import lombok.Builder;
import lombok.Data;
import lombok.ToString;

/**
 * @author vincent
 * @date 2019/9/6
 * @description
 * RESTful api 统一返回消息体
 */
@Data
@Builder
@ToString
public class Msg<T> {
    /**
     * 成功状态码
     */
    public static final int STATUS_SUCCESS = 0;
    /**
     * 失败状态码
     */
    public static final int STATUS_ERROR = 1;
    /**
     * 状态码
     */
    private int status = STATUS_SUCCESS;
    /**
     * 状态描述信息
     */
    private String memo = "";
    /**
     * 返回数据体
     */
    private T result;

    public static <T> Msg success(T result) {
      return Msg.builder().result(result).build();
    };
    public static <T> Msg success() {
        return success(null);
    };

    public static <T> Msg error(String memo){
        return Msg.builder().status(STATUS_ERROR).memo(memo).build();
    }


}
